<?php
class GetAccessRuleComponent extends CApplicationComponent
{
    public function init() {
    }    
	
	public function get($arrViewAction=null,$arrUpdateAction=null)
	{								
										if($arrViewAction == null && $arrUpdateAction == null)
										{
											return array(array('deny'));	
										}
									   $viewAccess='no';
                                       $updateAccess='no';
                                       $admin_email = ApplicationSessions::run()->read('admin_email');
                                       $role_id = ApplicationSessions::run()->read('role_id');
                                       $superuser = ApplicationSessions::run()->read('superuser');
                                       $controllerName = Yii::app()->controller->id;
                                       $group_id = GroupControllerRelation::model()->findByAttributes(array('controller'=>$controllerName))->group_id;
										if(empty($group_id) || $group_id == 0 &&  empty($role_id) || $role_id == 0)
										{
											return array(array('deny'));	
										}
										else 
										{
                                       $objPermission = Permission::model()->findByAttributes(array('group_id'=>$group_id,'role_id'=>$role_id));
                                       $viewAccess=$objPermission->view_access;
                                       $updateAccess=$objPermission->update_access;                
                                       $allowView=array();
                                       $allowUpdate=array();
                                       
                                       
                                
                                       if($arrViewAction){
                                       if($viewAccess=='yes'){        
                                       $allowView=array('allow',
                                                        'actions'=>$arrViewAction,
                                                        'users'=>array('*'),
                                                        );        
                                       }
                               			else {
                               				        
                                       $allowView=array('deny',
                                                        'actions'=>$arrViewAction,
                                                        'users'=>array('*'),
                                                               );        
                                       
                               			}
                                       }
                                       if($arrUpdateAction){
                                  		 if($updateAccess=='yes'){
                                               $allowUpdate=array('allow',
                                                                       'actions'=>$arrUpdateAction,
                                                                       'users'=>array('*'),
                                                               );
                                               
                                       }
                                       else 
                                       {
                                       	 $allowUpdate=array('deny',
                                                                       'actions'=>$arrUpdateAction,
                                                                       'users'=>array('*'),
                                                               );
                                               
                                       }
                                       }  

                                       	
                                       return array($allowView,$allowUpdate);
								}//for checking group_id else close	
	}
    
	
}